package com.xuanwei.core.util;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;

/**
 * @Author jiangyong
 * @Description TODO 参数校验
 * @Date 2019/4/15 14:28
 **/
public class ParamUtil {

    public static boolean checkIsString(String s) {
        if (StringUtils.isEmpty(s)) {
            return false;
        }
        return true;
    }

    public static boolean checkIsPositiveInteger(Integer i) {
        if (i == null || i < 1) {
            return false;
        }
        return true;
    }

    public static boolean checkIsEmail(String s) {
        if(StringUtils.isEmpty(s)){
            return false;
        }
        if(s.matches("^([a-z0-9A-Z]+[-|\\\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\\\.)+[a-zA-Z]{2,}$")){
            return true;
        }else {
            return false;
        }
    }

    public static boolean checkIsPhone(String s) {
        if(StringUtils.isEmpty(s)){
            return false;
        }
        if(s.matches("^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\\\D])|(18[0,5-9]))\\\\d{8}$")){
            return true;
        }else {
            return false;
        }

    }

    public static boolean checkIsIDCard(String s) {
        if(StringUtils.isEmpty(s)){
            return false;
        }
        if(s.matches("(^\\\\d{18}$)|(^\\\\d{15}$)")){
            return true;
        }else {
            return false;
        }

    }

    public static boolean checkIsURL(String s) {
        if(StringUtils.isEmpty(s)){
            return false;
        }
        if(s.matches("^((ht|f)tps?):\\/\\/([\\w\\-]+(\\.[\\w\\-]+)*\\/)*[\\w\\-]+(\\.[\\w\\-]+)*\\/?(\\?([\\w\\-\\.,@?^=%&:\\/~\\+#]*)+)?$")){
            return true;
        }else {
            return false;
        }

    }

    public static boolean checkIsUsername(String s) {
        if(StringUtils.isEmpty(s)){
            return false;
        }
        if(s.matches("^[a-zA-Z0-9]{4,16}$")){
            return true;
        }else {
            return false;
        }

    }

    public static boolean checkIsPassword(String s) {
        if(StringUtils.isEmpty(s)){
            return false;
        }
        if(s.matches("^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(.{8,20})$")){
            return true;
        }else {
            return false;
        }

    }


    public static boolean checkIsContainArray(Integer i, Integer... integers) {
        if (i == null) {
            return false;
        }
        boolean flag = false;
        for (Integer j : integers) {
            if (i .equals(j)) {
              flag=true;
              break;
            }
        }
        return flag;
    }
}
